class Solution:
    # 迭代
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        pre = None
        l = head
        while l:
            next_node = l.next
            l.next = pre
            pre = l
            l = next_node
        return pre


# 空间复杂度:O(1)
# 时间复杂度：O(n) 1 2 3 4 5
